- name: make the app be real
  hosts: os_control[0]:os_control_stg[0]
  user: root
  gather_facts: False

  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - /srv/private/ansible/vars.yml
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  roles:
    - role: rabbit/queue
      username: "resultsdb{{ env_suffix }}_ci_listener"
      queue_name: "resultsdb{{ env_suffix }}_ci_listener"
      routing_keys:
        - 'org.centos.*.ci.pipeline.allpackages-build.complete'
        - 'org.centos.*.ci.pipeline.allpackages-build.image.complete'
        - 'org.centos.*.ci.pipeline.allpackages-build.package.test.functional.complete'
        - 'org.centos.*.ci.pipeline.allpackages-build.package.complete'
        - 'org.centos.*.ci.pipeline.allpackages-build.package.ignored'
        - 'org.centos.*.ci.koji-build.test.queued'
        - 'org.centos.*.ci.koji-build.test.running'
        - 'org.centos.*.ci.koji-build.test.complete'
        - 'org.centos.*.ci.koji-build.test.error'
      sent_topics: ^$

    # The openshift/project role breaks if the project already exists:
    # https://pagure.io/fedora-infrastructure/issue/6404
    - role: openshift/project
      app: resultsdb-ci-listener
      description: resultsdb-ci-listener
      appowners:
        - ralph
        - mjia
        - dcallagh
        - gnaponie
        - cverna
        - pingou
        - lholecek
        - vmaljulin
        - lrossett
      tags:
        - apply-appowners

    - role: openshift/secret-file
      app: resultsdb-ci-listener
      secret_name: resultsdb-ci-listener-fedora-messaging-key
      key: resultsdb-ci-listener.key
      privatefile: "rabbitmq/{{env}}/pki/private/resultsdb{{env_suffix}}.key"

    - role: openshift/secret-file
      app: resultsdb-ci-listener
      secret_name: resultsdb-ci-listener-fedora-messaging-crt
      key: resultsdb-ci-listener.crt
      privatefile: "rabbitmq/{{env}}/pki/issued/resultsdb{{env_suffix}}.crt"

    - role: openshift/secret-file
      app: resultsdb-ci-listener
      secret_name: resultsdb-ci-listener-fedora-messaging-ca
      key: resultsdb-ci-listener.ca
      privatefile: "rabbitmq/{{env}}/pki/ca.crt"

    - role: openshift/object
      app: resultsdb-ci-listener
      template: secrets.yml
      objectname: secrets.yml

    - role: openshift/object
      app: resultsdb-ci-listener
      template: configmaps.yml
      objectname: configmaps.yml

    - role: openshift/object
      app: resultsdb-ci-listener
      template: deploymentconfigs.yml
      objectname: deploymentconfigs.yml
